<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>医院管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/style/admin.css" media="all">
</head>

<body>

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">关键字：</label>
                        <div class="layui-input-block">
                            <input type="text" name="keywords" placeholder="可按医院名搜索" autocomplete="off"
                                class="layui-input" style="width: 600px;">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-card-body">

                <div style="padding-bottom: 10px;">
                    {if (buttonAuth('hospital/add'))}
                    <button class="layui-btn layui-btn-normal layuiadmin-btn-order" data-type="add"><i
                            class="layui-icon">&#xe654;</i> 添加医院</button>
                    {/if}
                </div>

                <table id="LAY-user-table" lay-filter="LAY-user-table"></table>
                <script type="text/html" id="zizeng">
                    {{d.LAY_TABLE_INDEX+1}}
                </script>
                <script type="text/html" id="titleTpl">
                    {{#  if(d.ispic == 1){ }}
                    <div>{{d.title}} <i class="layui-icon">&#xe64a;</i></div>
                    {{#  } else { }}
                    <div>{{d.title}}</div>
                    {{#  } }}
                </script>
                <script type="text/html" id="table-seller-admin">
                    {if (buttonAuth('hospital/detail'))}
                    <a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-radius" lay-event="detail"><i
                            class="layui-icon layui-icon-face-smile-b"></i>查看</a>
                    {/if}
                    {if (buttonAuth('hospital/edit'))}
                    <a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-radius" lay-event="edit"><i
                            class="layui-icon layui-icon-edit"></i>编辑</a>
                    {/if}
                    {if (buttonAuth('hospital/del'))}
                    <a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-radius" lay-event="del"><i
                            class="layui-icon layui-icon-delete"></i>删除</a>
                    {/if}
                    <a class="layui-btn layui-btn-xs layui-btn-radius" lay-event="syncPrice"><i
                            class="layui-icon layui-icon-edit"></i>同步价格</a>
                    <a class="layui-btn layui-btn-xs layui-btn-radius" lay-event="syncModel"><i
                            class="layui-icon layui-icon-edit"></i>同步设备</a>
                    <a class="layui-btn layui-btn-xs layui-btn-radius" lay-event="syncAddress"><i
                            class="layui-icon layui-icon-edit"></i>同步地址</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="syncInsert"><i
                            class="layui-icon layui-icon-edit"></i>插入数据</a>
                </script>

            </div>
        </div>
    </div>

    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/common/js/layTool.js"></script>
    <script src="/static/common/js/jquery.min.js"></script>

    <script>
        layui.config({
            base: '/static/admin/'
        }).use(['table', 'util'], function () {
            var $ = layui.$,
                form = layui.form,
                table = layui.table,
                util = layui.util;

            var active = {
                add: function () {
                    layTool.open("{:url('hospital/add')}", "添加医院", '60%', '90%');
                }
            };

            $('.layui-btn.layuiadmin-btn-order').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            // 监听搜索
            form.on('submit(LAY-user-back-search)', function (data) {
                var field = data.field;

                // 执行重载
                table.reload('LAY-user-table', {
                    where: field
                });
            });
        });

        renderTable();
        // 渲染表格
        function renderTable() {
            layTool.table("#LAY-user-table", "/admin/hospital/index", [
                [
                    {field: 'zizeng', width: 80, title: '编号', sort: true, templet: '#zizeng'},
                    {field: "title", title: "医院名", width: 300, templet: '#titleTpl'},
                    {field: "ftitle", title: "副标题", width: 300},
                    {field: "classid", title: "栏目", width: 120},
                    {field: "price", title: "全身价格", width: 120},
                    {field: "kind", title: "医院类型", width: 120},
                    {field: "model", title: "设备型号", width: 150},
                    {field: "worktime", title: "工作时间", width: 180},
                    {field: "onclick", title: "点击数", sort: true, width: 100},
                    {field: "truetime", title: "发布时间", width: 170, templet: "<div>{{layui.util.toDateString(d.truetime*1000, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                    {field: "username", title: "添加人", width: 100,},
                    {title: "操作", align: "center", fixed: "right", toolbar: "#table-seller-admin",minWidth: 600}
                ]
            ], 20);


            layui.use(['table', 'layer'], function () {
                let layer = layui.layer;
                let table = layui.table;


                table.on("tool(LAY-user-table)",
                    function (e) {
                        if ("del" === e.event) {

                            layer.ready(function () {
                                var index = layer.confirm('您确定要删除该医院？', {
                                    title: '友情提示',
                                    icon: 3,
                                    btn: ['确定', '取消']
                                }, function () {

                                    $.getJSON('{:url("hospital/del")}', {
                                        id: e.data.id
                                    }, function (res) {

                                        if (0 == res.code) {

                                            layer.msg(res.msg);
                                            setTimeout(function () {
                                                renderTable();
                                            }, 300);
                                        } else {
                                            layer.alert(res.msg);
                                        }
                                    });
                                }, function () {

                                });
                            });
                        } else if ("edit" === e.event) {
                            layTool.open("/admin/hospital/edit/id/" + e.data.id, "编辑医院", '50%', '66%');
                        } else if ("detail" === e.event) {
                            layTool.open("/admin/hospital/detail/id/" + e.data.id, "查看医院", '100%', '100%');
                        } else if ("syncPrice" === e.event) {
                            layTool.open("/admin/hospital/syncPrice/ftitle/" + e.data.ftitle, "同步价格", '40%', '20%');
                        } else if ("syncModel" === e.event) {
                            layTool.open("/admin/hospital/syncModel/ftitle/" + e.data.ftitle, "同步设备型号", '40%', '20%');
                        } else if ("syncAddress" === e.event) {
                            layTool.open("/admin/hospital/syncAddress/ftitle/" + e.data.ftitle, "同步医院地址", '40%', '20%');
                        } else if ("syncInsert" === e.event) {
                            layTool.open("/admin/hospital/syncInsert/ftitle/" + e.data.ftitle, "插入数据", '40%', '20%');
                        }
                    });
            });
        }
    </script>
</body>

</html>